package com.jfree.demo;

import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Validator;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;

/**
 * @author wangjian
 * @date 2019/8/23 11:26
 */
@RestController
@RequestMapping("/es")
public class EsController {

    @Autowired
    Validator validator;

@Autowired
private RestHighLevelClient client;

    @PostMapping("/get")
    public void get(String route) throws IOException {
        ArrayList
        //TODO 多个索引如何查询？？？ 父子查询，嵌套查询  mapping？？？
        SearchRequest request=new SearchRequest("")
                .types("")
           .routing(route)
           .preference("");//TODO ???
        SearchSourceBuilder search=new SearchSourceBuilder();
        request.source(search);
        search.fetchSource();
        SearchResponse response= client.search(request, RequestOptions.DEFAULT);
        MatchQueryBuilder matchQueryBuilder=new MatchQueryBuilder("","");
        matchQueryBuilder.operator(Operator.AND);
        matchQueryBuilder.fuzziness(Fuzziness.AUTO);
        matchQueryBuilder.prefixLength(3);
        matchQueryBuilder.prefixLength(3);
        QueryBuilder  ma=QueryBuilders.matchQuery("", "").fuzziness(Fuzziness.AUTO);
    }

    public static void main(String[] args) throws IOException {
      String srt=  java.net.URLEncoder.encode("http://10.171.0.23:80/davinci-portal/portal/fileManager/imgByPath?path=regImage/9e8e490229c343f28ca11b0e0da96be3");
        System.out.println(Files.readAllBytes(Paths.get(srt)));
    }
}
